package com.huatai.bi.xxljob;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.huatai.bi.kafaka.SyncDataSetService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.huatai.bi.xxljob
 * @Author: hecaiy
 * @CreateTime: 2024-07-06  12:08
 * @Description: TODO xxl-job  任务调度handler
 * @Version: 1.0
 */
@Slf4j
@Component
public class DataSetXxlJob {
	@Autowired
	SyncDataSetService syncDataSetService;

	/**
	 * sql数据同步方法
	 * @throws Exception
	 */
	@XxlJob("SqlHandler")
	public void sqlJobHandler()throws Exception{
		log.debug("sql 数据同步方法执行");
		String jobParam = XxlJobHelper.getJobParam();
		JSONObject jsonObject = JSONObject.parseObject(jobParam);
		Long dtId = jsonObject.getLong("dtId");
		if(ObjectUtil.isNotEmpty(dtId)){
			syncDataSetService.synDataSet(dtId,false,null);
		}
	}

	/**
	 * python数据同步方法
	 *
	 * @throws Exception
	 */
	@XxlJob("PythonHandler")
	public void pythonJobHandler()throws Exception{
		log.debug("python 数据同步方法执行");
		String jobParam = XxlJobHelper.getJobParam();
		JSONObject jsonObject = JSONObject.parseObject(jobParam);
		Long dtId = jsonObject.getLong("dtId");
		if(ObjectUtil.isNotEmpty(dtId)){
			syncDataSetService.synDataSet(dtId,false,null);
		}
	}
}
